<?php
/**
 * created by zzy
 * date: 2018/1/26 14:04
 */
namespace App\Eloquent\Ygt;

class SaleCustomer extends DbEloquent{

    protected $table    = 'ygt_sale_customer';
    public static $tableFieldList   = [
        ['name'=>'id','title'=>'','value'=>0,'is_must'=>0],
        ['name'=>'username','title'=>'客户名称','value'=>'','is_must'=>1],
        ['name'=>'first_letter','title'=>'客户名称','value'=>'','is_must'=>1],
        ['name'=>'mobile','title'=>'客户电话','value'=>'','is_must'=>1],
        ['name'=>'user_id','title'=>'客户电话','value'=>0,'is_must'=>1],
        ['name'=>'province_id','title'=>'客户地址','value'=>0,'is_must'=>1],
        ['name'=>'city_id','title'=>'客户地址','value'=>0,'is_must'=>1],
        ['name'=>'area_id','title'=>'客户地址','value'=>0,'is_must'=>1],
        ['name'=>'address','title'=>'客户地址','value'=>'','is_must'=>0],
        ['name'=>'province_name','title'=>'客户地址','value'=>'','is_must'=>1],
        ['name'=>'city_name','title'=>'客户地址','value'=>'','is_must'=>1],
        ['name'=>'area_name','title'=>'客户地址','value'=>'','is_must'=>1],
    ];

    public static function edit($data,$pk='')
    {
        $id                 = isset($data['id']) ? intval($data['id']) : 0;
        if($id>0){
            $where          = ['id'=>$id];
            $result         = self::updateOneData($where, $data,$pk);
        } else {
            $result         = self::insertOneData($data,$pk);
        }
        return $result;
    }
    public static function getListJoinRelation($whereArr,$fields='',$limit=0,$offset=0)
    {
        $orderby            = ['ygt_sale_customer.id','desc'];
        $fieldL             = 'ygt_sale_customer_relation.sale_customer_id';
        $fieldR             = 'ygt_sale_customer.id';
        $join               = [
            ['table'=>'ygt_sale_customer_relation', 'field_l'=>$fieldL, 'field_c'=>'=', 'field_r'=>$fieldR]
        ];
        $result             = self::getList($whereArr,$fields,$limit,$offset,$orderby,'',$join);
        return $result;
    }

}

